﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Linq;
using System.Xml.Linq;
using System.Reflection;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceReference1.Mage_Api_Model_Server_HandlerPortTypeClient client = new ServiceReference1.Mage_Api_Model_Server_HandlerPortTypeClient();

            // Get Username and password from user
            Console.Write("Magento Username:");
            string username = Console.ReadLine();

            Console.Write("Password:");
            string password = Console.ReadLine();

            Console.WriteLine();
            Console.WriteLine("Trying to login...");

            // SessionID, resourcePath
            string sessionId = client.login(username, password);
            Console.WriteLine("Login successful..." + Environment.NewLine + "Getting customer list");
            string resourcePath = "customer.list";

            // Make a SOAP V1 service request for Call method with session id, resource path but without any arguments as of now.
            List<Customer> customers = SoapHelper.Instance.CallToList<Customer>(sessionId, resourcePath);

            // Show downloaded customers.
            Console.WriteLine(customers.Count() + " Customers downloaded." + Environment.NewLine);
            int i = 1;
            foreach (var item in customers)
            {
                Console.WriteLine(i.ToString() + " " + item.firstname + " " + item.lastname);
                i++;
            }

            List<Country> countries = SoapHelper.Instance.CallToList<Country>(sessionId, "country.list");
            Console.ReadKey();
        }
    }
}
